package com.xzp.bams.entity;

/**
 * @TODO
 * @Author xu
 * 2025/3/7
 */
public class CreditAccount extends Account {
    private double ceiling;

    public CreditAccount() {
    }

    public CreditAccount(Long id, String password, String name, String personId, String email, double balance, double ceiling) {
        super(id, password, name, personId, email, balance);
        this.ceiling = ceiling;
    }


    public CreditAccount(double ceiling) {
        this.ceiling = ceiling;
    }

    /**
     * 获取
     *
     * @return ceiling
     */
    public double getCeiling() {
        return ceiling;
    }

    /**
     * 设置
     *
     * @param ceiling
     */
    public void setCeiling(double ceiling) {
        this.ceiling = ceiling;
    }

    @Override
    public Account withdraw(double money) {  //500  1500  800
        if (getBalance() + ceiling >= money) {
            if (this.getBalance() >= money) {
                this.setBalance(this.getBalance() - money);
            } else {
                this.ceiling = this.getBalance() - money + ceiling;
                this.setBalance(0.0);
            }
        } else {
            System.out.println("超出额度");
        }
        return this;
    }

    @Override
    public String toString() {
        return  super.toString() +
                " , ceiling=" + ceiling +
                "} ";
    }
}
